package com.hxjc.bankagent.old.bank.service.outbound;

import com.cmbc.afw.outbound.OutBoundUtils;
import com.cmbc.afw.util.tx.message.Response;
import com.cmbc.afw.utils.exception.PlatException;
import com.hxjc.bankagent.old.bank.entity.BankRequest;
import com.hxjc.bankagent.old.bank.entity.BankResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cmbc.afw.outbound.OutBoundHeader;

/**
 * BankOutboundService
 *
 * @author yinz
 * @date 2018/5/8
 */
public class BankOutboundService {

    private static Logger logger = LoggerFactory.getLogger(BankOutboundService.class);

    public BankResponse execute(BankRequest outboundRequest) {

        logger.debug("进入DemoBankOutboundService交易");

        String transcode = "DemoBankOutboundService";
        String reqSeq = "outboundsvc1234567890123";
        String merchantNum = "ecpwg";

        OutBoundHeader header = new OutBoundHeader(transcode, reqSeq, merchantNum);
        Response response = null;
        try {
            response = OutBoundUtils.execute(header, outboundRequest);
        } catch (Throwable t) {
            t.printStackTrace();
            logger.error("外部服务调用失败", t);
            throw new PlatException("YASFOUT0001", "外部服务调用失败");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("得到的响应为：" + response.toString());
        }
        //需要做业务处理
//		DemoBankOutboundResponse outboundResponse = (DemoBankOutboundResponse) response.getBody();
//		outboundResponse.setParam1(param1 + " outbound");
        logger.debug("退出DemoBankOutboundService交易");
//		return outboundResponse;
        return null;
    }
}
